<?php
//代理商结算管理
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
//展示页
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	//查询
	//审核状态
	if(!empty($_RQ['status'])){
		$params['status']=trim($_RQ['status']);
		$return['params']['status']=$params['status'];
	}
	//打款状态
	if(!empty($_RQ['ispay'])){
		$params['ispay']=trim($_RQ['ispay']);
		$return['params']['ispay']=$params['ispay'];
	}
	//支付订单
	if(!empty($_RQ['trade_id'])){
		$params['trade_id']=trim($_RQ['trade_id']);
		$return['params']['trade_id']=$params['trade_id'];
	}
	$fields=array('id','ordersn','money','status','ispay','createtime','pay_type','trade_id');
    $orderby='id desc';
	$total='';
	//$parameter=array('params'=>$params,'limit'=>array($pindex,$psize),'fields'=>array('id','uniacid','order_id','money','status','clearsn','createtime'));
	$list = pdo_getslice('core_agent_clear',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	if($list){
		foreach($list as &$item){

		}
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['list']=$list?$list:array();
	$htmls=array(array('type' =>'list','tabs'=>array(
			 array('op'=>'list','title'=>'代理商结算管理'),
			),
			'list' =>array ('data' => 'list','list' => array (0 => array (
		        array('title' => 'id','name' => 'id', 'type' => 'string',),),
		         array (array ('title' => '结算单号','name' => 'ordersn','type' => 'string',),),
				array(array('title' => '结算金额','name' => 'money','type' => 'string',),),
		         array (array ('title' => '审核状态','name' => 'status','type' => 'radio','options' => 'status_xuanxiang',), ),
		         array (array ('title' => '打款状态','name' => 'ispay','type' => 'radio','options' => 'ispay_xuanxiang',), ),
		         array (array ('title' => '支付方式','name' => 'pay_type','type' => 'radio','options' => 'pay_type_xuanxiang',), ),
				 array (array ('title' => '支付单号','name' => 'trade_id','type' => 'string', ),),
				array (array ('title' => '结算时间','name' => 'createtime','type' => 'time', ),),
				),
			   'delall'=>true,
		       'del_one'=>true,
		       'edit'=>false,
		       'action'=>array(
					array('type'=>'post','op'=>'money','title'=>'申请打款','message'=>'确定申请打款？','show'=>array('status'=>1,'ispay'=>'0')),
				),
		        ),
		'search' => array(
			array ( 'type'=>'radio','width'=>15,'title'=>'审核状态','name' => 'status','options'=>'status_xuanxiang'),
			array ( 'type'=>'radio','width'=>15,'title'=>'打款状态','name' => 'ispay','options'=>'ispay_xuanxiang'),
			array ( 'type'=>'string','width'=>15,'title'=>'支付订单','name' => 'trade_id'),
		),
		),
	    );
	$return['htmls']=$htmls;
	$return['status_xuanxiang']=array (0 => '待审核',1=>'审核通过');
	$return['ispay_xuanxiang']=array (0 => '待申请',1 => '等待打款',2=>'打款完成');
	$return['pay_type_xuanxiang']=array (0 => '支付宝支付',1 => '微信支付',2=>'银联支付');
	exi($return);
}

//申请打款
if($_RQ['op']=='money'){
	
	$id=intval($_RQ['id']);

	if($id){
		pdo_update('core_agent_clear',array('ispay'=>'1'),array('id'=>$id));	
	
	exi('申请打款成功！');
	}
	else{
		
		exi('申请打款失败，请重试','error');
	}
}
